package com.zhilianbao.leyaogo.utils;

/**
 * ClassName: LoginCodeBlock <br>
 * Description: 逻辑代码块执行<br>
 * Author: Cyarie <br>
 * Created: 2017/1/4 15:21 <br>
 * Update Time：<br>
 * Update Description：<br>
 */
public class LogicCodeBlock {

    private LogicCodeBlockCallback mLogicCodeBlockCallback;


    public interface LogicCodeBlockCallback {

        void next(int logicState);
    }


    /**
     * 逻辑状态枚举类型
     */
    public enum LogicState {
        None(0),
        /**
         * 充值有礼
         */
        Recharge(1),

        /**
         * 加入购物车
         */
        AddToCart(2),

        /**
         * 收藏商品
         */
        CollectGoods(3);

        LogicState(int value) {
            this.value = value;
        }

        public int value;
    }

    public static LogicCodeBlock create() {
        return LogicCodeBlock.LoginCodeBlockHolder.sInstance;
    }

    private static class LoginCodeBlockHolder {
        public static LogicCodeBlock sInstance = new LogicCodeBlock();
    }

    /**
     * 注册逻辑代码块回调
     *
     * @param callback
     */
    public void registerLogicCodeCallback(LogicCodeBlockCallback callback) {
        if (mLogicCodeBlockCallback != null)
            mLogicCodeBlockCallback = null;
        this.mLogicCodeBlockCallback = callback;
    }


    /**
     * 分发逻辑代码
     *
     * @param logicState
     */
    public void dispatchLogicCode(int logicState) {
        if (mLogicCodeBlockCallback != null)
            mLogicCodeBlockCallback.next(logicState);
    }


}
